package com.fulu.game.bi.common.util.lang;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.UUID;

public class GenIdUtil {
    private static final String SALT = "";
    private static final String CHANNEL_PRE = "KHPW";

    private static String prefix;

    private static void setPrefix(String prefix) {
        GenIdUtil.prefix = prefix;
    }

    @Component
    public static class EnumConfig {

        /**  获取环境定义的前缀 */
        @Value("${config.evn.prefix}")
        private String prefix;

        @PostConstruct
        public void postConstruct() {
            GenIdUtil.setPrefix(this.prefix);
        }
    }
    public GenIdUtil() {
    }

    public static String GetToken() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String GetTokenWithUserId(Integer userId) {
        return UUID.randomUUID().toString().replace("-", "") + "#" + userId;
    }

    public static String GetGUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String GetOrderNo() {
        String date = DateUtil.format(new Date(), "yyMMdd");
        String randomNum = RandomUtil.randomNumbers(6);
        String evn = prefix;
        return "PROD".equals(evn) ? date + randomNum : evn + date + randomNum;
    }

    public static String GetRoomNo() {
        String randomNum = RandomUtil.randomNumbers(6);
        String evn = prefix;
        return "PROD".equals(evn) ? randomNum : evn + randomNum;
    }

    public static String GetVisitorNo() {
        String randomNum = RandomUtil.randomNumbers(7);
        return randomNum;
    }

    public static String GetCouponNo() {
        String date = DateUtil.format(new Date(), "yyMMdd");
        String randomStr = RandomUtil.randomNumbers(7);
        return date + randomStr;
    }

    public static String GetImgNo() {
        return RandomUtil.randomNumbers(7);
    }

    public static String getAppid() {
        return "KHPW#" + System.currentTimeMillis();
    }

    public static String getAppkey() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String getCdkSeries() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String get7RandomNumber() {
        return null;
    }
}
